import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class A537 {
	public static boolean primeDetermine(int n) {
		if(n == 1)
			return false;
		else if(n == 2 || n == 3)
			return true;
		else if(n % 2 == 0)
			return false;
		else {
			int end = (int)Math.sqrt(n);
			for(int i = 3; i <= end; i += 2) {
				if(n % i == 0)
					return false;
			}
			return true;
		}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder output;
		String input;
		int t;
		int counter;
		char[] lineChars;
		boolean hasPrime;
		
		while((input = br.readLine()) != null) {
			t = Integer.parseInt(input);
			for(int c = 1; c <= t; c++) {
				input = br.readLine();
				lineChars = input.toCharArray();
				Arrays.sort(lineChars);
				
				output = new StringBuilder();
				output.append("Case " + c + ": ");
				
				counter = 0;
				hasPrime = false;
				for(int i = 0; i < lineChars.length - 1; i++) {
					counter++;					
					if(lineChars[i] != lineChars[i + 1]) {
						if(primeDetermine(counter)) {
							output.append(Character.toString(lineChars[i]));
							hasPrime = true;
						}
						counter = 0;
					}
				}
				
				if(lineChars.length > 1) {
					if(lineChars[lineChars.length - 2] == lineChars[lineChars.length - 1]) {
						counter++;	
						if(primeDetermine(counter)) {
							output.append(Character.toString(lineChars[lineChars.length - 1]));
							hasPrime = true;
						}
					}
				}
				
				if(!hasPrime)
					output.append("empty");
				
				System.out.println(output);
			}
		}
	} // end of main
} // end of class A537